package main

import (
	"fmt"
	"sync"

	hprose "github.com/hprose/hprose-golang/rpc"
)

var (
	QuestAll = 0
	Lock     sync.Mutex
)

type EchoRequest struct {
	S string `simple:"true"`
}

type EchoRespone struct {
	Res int64 `simple:"true"`
}

func Echo(req *EchoRequest) (*EchoRespone, error) {
	Lock.Lock()
	defer Lock.Unlock()
	QuestAll++
	if QuestAll%10000 == 0 {
		fmt.Println("nun cur: is", QuestAll)
	}
	return &EchoRespone{Res: int64(QuestAll)}, nil
}

func main() {
	uri := "tcp://" + "127.0.0.1" + ":" + "8000" + "/"
	server := hprose.NewTCPServer(uri)
	server.AddFunction("Echo", Echo)
	server.Start()
}
